`:top
The `!Object Constraint Language`! (`!OCL`!) is a `F33f`_`[declarative language`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Declarative_language]`_`f describing rules applying to `F33f`_`[Unified Modeling Language`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Unified_Modeling_Language]`_`f (UML) models developed at `F33f`_`[IBM`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=IBM]`_`f and is now part of the UML standard. Initially, OCL was merely a formal specification language extension for UML.`:cite-ref-1[`F5bf`_`[1`#cite-note-1]`_`f] OCL may now be used with any `F33f`_`[Meta-Object Facility`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Meta-Object_Facility]`_`f (MOF) `F33f`_`[Object Management Group`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Object_Management_Group]`_`f (OMG) `F33f`_`[meta-model`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Meta-model]`_`f, including UML.`:cite-ref-2[`F5bf`_`[2`#cite-note-2]`_`f] The Object Constraint Language is a precise text language that provides constraint and object query expressions on any MOF model or meta-model that cannot otherwise be expressed by diagrammatic notation. OCL is a key component of the new OMG standard recommendation for transforming models, the Queries/Views/Transformations (`F33f`_`[QVT`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=QVT]`_`f) specification.
>>Contents
• `F0af`_`[Description`#description]`_`f
• `F0af`_`[Relation`#relation]`_`f
• `F0af`_`[OCL and UML`#ocl-and-uml]`_`f
• `F0af`_`[OCL and MOF`#ocl-and-mof]`_`f
• `F0af`_`[OCL and QVT`#ocl-and-qvt]`_`f
• `F0af`_`[Alternatives`#alternatives]`_`f
• `F0af`_`[Extensions`#extensions]`_`f
• `F0af`_`[See also`#see-also]`_`f
• `F0af`_`[References`#references]`_`f
• `F0af`_`[External links`#external-links]`_`f
-─
>>Description
OCL is a descendant of `F33f`_`[Syntropy`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Syntropy_(Software)]`_`f, a second-generation object-oriented analysis and design method. The OCL 1.4 definition specified a constraint language. In OCL 2.0, the definition has been extended to include general object query language definitions.`:cite-ref-foldoc-3-0[`F5bf`_`[3`#cite-note-foldoc-3]`_`f]
OCL statements are constructed in four parts:
1. a context that defines the limited situation in which the statement is valid
2. a property that represents some characteristics of the context (e.g., if the context is a class, a property might be an attribute)
3. an operation (e.g., arithmetic, set-oriented) that manipulates or qualifies a property, and
4. keywords (e.g., if, then, else, and, or, not, implies) that are used to specify conditional expressions.
>>Relation
>>>OCL and UML
OCL supplements UML by providing expressions that have neither the ambiguities of natural language nor the inherent difficulty of using complex mathematics.`:cite-ref-foldoc-3-1[`F5bf`_`[3`#cite-note-foldoc-3]`_`f] OCL is also a navigation language for graph-based models.
>>>OCL and MOF
OCL makes a `F33f`_`[Meta-Object Facility`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Meta-Object_Facility]`_`f model more precise by associating assertions with its meta-elements.
>>>OCL and QVT
Of particular importance to `F33f`_`[Model Driven Engineering`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Model_Driven_Engineering]`_`f (MDE) or `F33f`_`[model-driven architecture`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Model-driven_architecture]`_`f is the notion of `F33f`_`[Model transformation`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Model_transformation]`_`f. The `F33f`_`[OMG`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Object_Management_Group]`_`f has defined a specific standard for model transformation called `!MOF/QVT`! or in short `F33f`_`[QVT`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=QVT]`_`f. Several model transformation languages like `F33f`_`[GReAT`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=GReAT]`_`f, `F33f`_`[VIATRA`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=VIATRA]`_`f, or `F33f`_`[Tefkat`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Tefkat]`_`f are presently available, with different levels of compliance with the QVT standard. Many of these languages are built on top of OCL, which is the main part of the `F33f`_`[QVT`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=QVT]`_`f-compliance.
>>Alternatives
Being a rule-based validation language, `F33f`_`[Schematron`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Schematron]`_`f may be considered an alternative to OCL. However Schematron works for Extensible Markup Language `F33f`_`[(XML) trees`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=XML_tree]`_`f while OCL makes it possible to navigate `F33f`_`[MOF`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Meta-Object_Facility]`_`f-based models and meta-models (i.e. XML Metadata Interchange (`F33f`_`[XMI`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=XML_Metadata_Interchange]`_`f) trees). In other words, OCL relates to UML or MOF similarly to how Schematron relates to `F33f`_`[XML`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=XML]`_`f. (Note that Schematron uses `F33f`_`[XPath`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=XPath]`_`f to navigate inside the XML trees.)
Being a model specification language permitting designers to decorate a model or a meta-model with side-effect-free annotations, OCL could be replaced by languages like `F33f`_`[Alloy`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Alloy_language]`_`f. Automated OCL generation is in principle possible from natural language.`:cite-ref-nl2ocl-4-0[`F5bf`_`[4`#cite-note-nl2ocl-4]`_`f]
`t
| Constraint | OCL Equivalent |
|---|---|
| The age of a person is not negative. | context Person inv : self.age >=0 |
| A person is younger than its parents. | context Person inv : self.parents->forAll(p/p.age>self.age) |
| After a birthday, a person becomes one year older. | context Person::hasBirthday() post : self.age=self.age@pre+1 |
| A Person has 2 parents at max. | context Person inv : self.parents->size()<=2 |
| After somebody has a child, his/her child-set is not empty, and it is larger than before. | context Person::getsChild() post : self.childs->notEmpty() and self.childs->size() > self.childs@pre->size() |
| Only an adult can be owner of a car. | context Person inv : self.age<18 implies self.cars->isEmpty() |
| The first registration of a car can not be before it is built. | context Auto inv : self.registration>=self.constructionYear |
| Every Person that has a car has at least one car which is younger than the Person. | context Person inv : self.cars->notEmpty() implies self.cars->exists( c / Calendar.YEAR - c.constructionYear < self.age) |
| Nobody can be his/her own parent. | context Person inv : self.parents->excludes(self) |
| There's at least one Person which owns a car. | context Person inv : Person.allInstances()->exists(p / p.cars->size() > 0) |
`t
>>Extensions
Eclipse OCL `:cite-ref-5[`F5bf`_`[5`#cite-note-5]`_`f] extends Standard OCL with additional operators and a type for Maps. AgileUML extends Standard OCL with Map and Function types.`:cite-ref-6[`F5bf`_`[6`#cite-note-6]`_`f] These extensions are consistent with the map and function types present in modern programming languages such as Python and Swift.
>>See also
• `F33f`_`[Computer model`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Computer_model]`_`f
• `F33f`_`[Data mapping`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Data_mapping]`_`f
• `F33f`_`[Domain Specific Language`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Domain_Specific_Language]`_`f (DSL)
• `F33f`_`[Domain-specific modelling`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Domain-specific_modelling]`_`f (DSM)
• `F33f`_`[Eclipse`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Eclipse_(software)]`_`f GMT Project
• `F33f`_`[Gello Expression Language`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Gello_Expression_Language]`_`f
• `F33f`_`[Glossary of Unified Modeling Language terms`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Glossary_of_Unified_Modeling_Language_terms]`_`f
• `F33f`_`[List of UML tools`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=List_of_UML_tools]`_`f
• `F33f`_`[Meta-modeling`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Meta-modeling]`_`f
• `F33f`_`[Meta-modeling technique`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Meta-modeling_technique]`_`f
• `F33f`_`[Meta-Object Facility`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Meta-Object_Facility]`_`f (MOF)
• `F33f`_`[Metadata`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Metadata]`_`f
• `F33f`_`[Model-based testing`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Model-based_testing]`_`f (MBT)
• `F33f`_`[Model-driven architecture`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Model-driven_architecture]`_`f (MDA)
• `F33f`_`[Model Driven Engineering`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Model_Driven_Engineering]`_`f (MDE)
• `F33f`_`[Model Transformation Language`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Model_Transformation_Language]`_`f (MTL)
• `F33f`_`[Modeling language`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Modeling_language]`_`f
• `F33f`_`[Modeling perspectives`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Modeling_perspectives]`_`f
• `F33f`_`[MOFM2T`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=MOFM2T]`_`f
• `F33f`_`[Object-oriented analysis and design`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Object-oriented_analysis_and_design]`_`f (OOAD)
• `F33f`_`[MOF Queries/Views/Transformations`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=QVT]`_`f (QVT)
• `F33f`_`[Semantic translation`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Semantic_translation]`_`f
• `F33f`_`[Transformation language`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Transformation_language]`_`f (TL)
• `F33f`_`[UML tool`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=UML_tool]`_`f
• `F33f`_`[Vocabulary-based transformation`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Vocabulary-based_transformation]`_`f
• `F33f`_`[XMI`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=XML_Metadata_Interchange]`_`f
• `F33f`_`[XML transformation language`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=XML_transformation_language]`_`f (XTL)
>>References
`:cite-note-1`!1.`! `F0af`_`[↑`#cite-ref-1]`_`f Object Management Group (OMG); `*Object Constraint Language Specification`*, Chapter 7 of `*OMG Unified Modeling Language Specification`*, Version 1.3, March 2000 (first edition)
`:cite-note-2`!2.`! `F0af`_`[↑`#cite-ref-2]`_`f Object Management Group (OMG); `*Object Constraint Language OMG Available Specification Version 2.0`*, May 2006
`:cite-note-foldoc-3`!3.`! `F0af`_`[↑`#cite-ref-foldoc-3-0]`_`f This article is based on material taken from Object+Constraint+Language at the `*`F33f`_`[Free On-line Dictionary of Computing`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Free_On-line_Dictionary_of_Computing]`_`f`* prior to 1 November 2008 and incorporated under the "relicensing" terms of the `F33f`_`[GFDL`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=GNU_Free_Documentation_License]`_`f, version 1.3 or later.
`:cite-note-nl2ocl-4`!4.`! `F0af`_`[↑`#cite-ref-nl2ocl-4-0]`_`f `:citerefimran-sarwar-bajwa2010`aImran Sarwar Bajwa (October 2010). "OCL Constraints Generation from Natural Language Specification, 2010". `F33f`_`[IEEE`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=IEEE]`_`f. `F33f`_`[doi`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Doi_(identifier)]`_`f:10.1109/EDOC.2010.33. `F33f`_`[S2CID`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=S2CID_(identifier)]`_`f 7495256. `B100`F9d9{{cite journal}}`f`b: Cite journal requires `B100`F9d9|journal=`f`b (help)
`:cite-note-5`!5.`! `F0af`_`[↑`#cite-ref-5]`_`f "Eclipse OCL™ (Object Constraint Language)". 31 January 2013.
`:cite-note-6`!6.`! `F0af`_`[↑`#cite-ref-6]`_`f `:citereflanokolahdouz-rahimi2021`aLano, Kevin; Kolahdouz-Rahimi, Shekoufeh (2021). "Extending OCL with Map and Function Types". `*Fundamentals of Software Engineering`*. Lecture Notes in Computer Science. Vol. 12818. pp. 108–123. `F33f`_`[doi`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Doi_(identifier)]`_`f:10.1007/978-3-030-89247-0_8. `F33f`_`[ISBN`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=ISBN_(identifier)]`_`f 978-3-030-89246-3. `F33f`_`[S2CID`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=S2CID_(identifier)]`_`f 239029860.
>>External links
• OMG OCL specification
• OCL Portal - The center for OCL related information
• OCL page of Computer Science Dept. of CSUSB (brief OCL 2.0 syntax)
• Octopus: OCL Tool for Precise Uml Specifications (OCL checker)
• Dresden OCL Toolkit (OCL Toolkit, various OCL related publications)
• HOL-OCL (An interactive theorem proof environment for OCL, various OCL related publications)
• OCL for Java tutorial on ParlezUML
• Article on using EMF's OCL in Java code
• UML link page on cetus-links.org
• USE (UML-based Specification Environment) (OCL Tool for model validation, various OCL related publications)
• OCL tutorial
• NL2OCL (OCL Tool for invariant generation from NL)
`c`F0af`_`[↑ Back to top`#top]`_`f`a